Repository navigation
Raise on asyncio.wait and as_completed in workflows - #2155
Open
prateek11rai wants to merge 2 commits into
Open
prateek11rai wants to merge 2 commits into
prateek11rai wants to merge 2 commits into
Conversation
VegetarianOrc
force-pushed
the
restrict-asyncio-wait-as-completed
branch
from
November 23, 2026 19:09
0bf9997 to
9624c39
Compare
The sandbox has warned on these set-based calls since 1.7.0; they now raise RestrictedWorkflowAccessError like other non-deterministic calls. Update the sandbox test and the README example to match. Closes temporalio#535 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alex Mazzeo <alex.mazzeo@outlook.com>
VegetarianOrc
force-pushed
the
restrict-asyncio-wait-as-completed
branch
from
November 24, 2026 23:06
6186099 to
181992d
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
🤖
claude-opus-5-5on behalf of PrateekWhat was changed
Calling
asyncio.as_completed()orasyncio.wait()inside a workflow now raisesRestrictedWorkflowAccessError. Before, the sandbox only printed a warning. The error message tells you what to use instead:workflow.as_completed()orworkflow.wait().Files:
temporalio/worker/workflow_sandbox/_restrictions.py: removedleaf_warning=UserWarningfrom the two matchers, so they raise like other restricted calls.tests/worker/workflow_sandbox/test_runner.py: updatedtest_workflow_sandbox_bad_asyncioto expect the error instead of the warnings.README.md: theGreetingWorkflowexample now usesworkflow.wait(it would fail otherwise; same fix as Use workflow.wait in README GreetingWorkflow example #2091), and the asyncio section says the sandbox raises.changelog/breaking-changes/impatient-hourglass-heron.md: release note.Why?
Both functions put tasks in a
set. A set's order depends on memory addresses, which differ between workers, so a workflow can issue its commands in a different order on replay and fail with a nondeterminism error.The warning was added in 1.7.0 (August 2024) as a first step. That release's notes said: "In a future release it will be an error to use non-deterministic versions from
asyncio." This PR makes that change, as planned in #535.What users will notice:
asyncio.waittoworkflow.waitcan change the order of its commands, so the release note recommends doing it with versioning (patching).asyncio.TaskGroupstays a warning. Its warning only shipped in 1.36.0 (Warn against asyncio TaskGroup in workflows #2085), and there is no deterministic replacement yet.Checklist
Closes [Feature Request] Turn invalid asyncio call warnings into errors #535
How was this tested:
The updated test runs twice, once for
as_completedand once forwait. Each run checks that the workflow fails withRestrictedWorkflowAccessErrorand that the message names theworkflow.replacement.mainDID NOT RAISE WorkflowFailureErrortests/worker/workflow_sandboxmain; the old test is now two)I also ran the full suite on
mainand on this branch and compared the results: no test fails only on this branch. Both runs had unrelated failures, mostly Nexus tests, because I used Homebrew'stemporaldev server (1.9.1) instead of the build the tests download.poe lintpasses.Run on macOS arm64, Python 3.13.3, with
-E localhost:7233.Any docs updates needed?
README updated in this PR, plus the changelog fragment.